package operation;

import Dao.OrderDao;
import interfac.OrderOperation;
import pojo.MilkTeaProduct;
import pojo.Order;

import java.util.List;
import java.util.Scanner;

public class UpdateOrderStatusOperation implements OrderOperation {
    @Override
    public void execute(Scanner scanner) {
        show_order_status();
        System.out.println("请输入要完成的订单ID:");
        OrderDao orderDao = new OrderDao();
        int orderId = scanner.nextInt();
        boolean success = orderDao.updateOrderStatus(orderId);
        if (success) {
            System.out.println("订单已成功标记为已完成。");
        } else {
            System.out.println("未能完成订单，请检查订单ID是否正确。");
        }
    }
    public static void show_order_status() {
        OrderDao orderDao = new OrderDao();
        List<Order> orders = orderDao.getOrdersStatus();
        System.out.println("未完成的订单列表如下：");
        for (Order order : orders) {
            System.out.println(order.getOrder_id() + "    " + order.getOrder_status() );
            System.out.println("订单:");
            List<MilkTeaProduct> products = order.getProducts();
            int[] quantities = order.getQuantities();

            // 检查产品列表和数量数组是否为空或长度不一致
            if (products == null || quantities == null || products.size() != quantities.length) {
                System.out.println("订单数据异常，无法显示详细信息。");
                continue;
            }

            for (int i = 0; i < products.size(); i++) {
                MilkTeaProduct product = products.get(i);
                int quantity = quantities[i];
                System.out.println(" - " + product.getProduct_name() + " x" + quantity);
            }

            System.out.println("----------------------");
        }
    }
}
